package com.example.choupaiapp.main.activity.mine;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.choupaiapp.R;
import com.example.choupaiapp.common.adapter.BaseAdapterHelper;
import com.example.choupaiapp.common.adapter.QuickAdapter;
import com.example.choupaiapp.common.constant.Contacts;
import com.example.choupaiapp.main.bean.SendCodeBean;
import com.example.choupaiapp.common.finalokgo.callback.Callback;
import com.example.choupaiapp.common.finalokgo.request.RequestType;
import com.example.choupaiapp.common.ui.activity.CommonActivity;
import com.example.choupaiapp.common.util.ContextUtil;
import com.example.choupaiapp.common.util.DialogUtil;
import com.example.choupaiapp.common.util.SharedPreferencesHelp;
import com.example.choupaiapp.common.util.Utils;
import com.example.choupaiapp.common.view.XGridView;
import com.example.choupaiapp.common.view.XListView;
import com.example.choupaiapp.main.activity.home.CameraActivity;
import com.example.choupaiapp.main.bean.InviteTopBean;
import com.example.choupaiapp.main.bean.SignBean;
import com.example.choupaiapp.main.bean.SignKeepBena;
import com.example.choupaiapp.main.bean.SignTaskBean;
import com.example.choupaiapp.main.bean.UserInfoBean;
import com.example.choupaiapp.main.callback.WechatCallBack;
import com.example.choupaiapp.main.constant.Config;
import com.example.choupaiapp.main.constant.Url;
import com.example.choupaiapp.main.util.WXShareUtil;
import com.example.choupaiapp.main.util.WechatLoginUtil;
import com.example.choupaiapp.main.view.ScaleLinearLayout;
import com.lzy.okgo.model.Response;
import com.sina.weibo.sdk.WbSdk;
import com.sina.weibo.sdk.api.TextObject;
import com.sina.weibo.sdk.api.WeiboMultiMessage;
import com.sina.weibo.sdk.auth.AuthInfo;
import com.sina.weibo.sdk.share.WbShareCallback;
import com.sina.weibo.sdk.share.WbShareHandler;
import com.sunfusheng.marqueeview.MarqueeView;
import com.tencent.connect.share.QQShare;
import com.tencent.connect.share.QzoneShare;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;
import com.umeng.analytics.MobclickAgent;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by ASUS on 2019/12/11.
 */

public class SignActivity extends CommonActivity implements WbShareCallback, WechatCallBack {

    @BindView(R.id.marqueeView)
    MarqueeView marqueeView;
    @BindView(R.id.gridview)
    XGridView gridview;
    @BindView(R.id.new_listview)
    XListView newListview;
    @BindView(R.id.quicken_card)
    TextView quickenCard;
    @BindView(R.id.date_listview)
    XListView dateListview;
    @BindView(R.id.keep_sign)
    TextView keep_sign;
    private Tencent mTencent;
    private QuickAdapter<SignTaskBean.EverydayListBean> dateAdapter;
    private QuickAdapter<SignTaskBean.NewListBean> newAdapter;
    private QuickAdapter<SignKeepBena> quickAdapter;
    private SignBean signBean;
    private UserInfoBean mUserInfoBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign);
    }

    @Override
    protected void initView() {
        setTitle("任务中心");

        mUserInfoBean = (UserInfoBean) SharedPreferencesHelp.getBean("userInfo");
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            signBean = (SignBean) bundle.getSerializable("signData");
            int isSign = bundle.getInt("isSign", 0);
            if (isSign == 2) {
                DialogUtil dialogUtil = new DialogUtil();
                dialogUtil.showCenterDialog(context, R.layout.dialog_sign_success);
                LinearLayout dialog_sign_success = (LinearLayout) dialogUtil.dialog_center_layout;
                dialog_sign_success.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (Utils.isDoubleClick()) {
                            return;
                        }
                        dialogUtil.dialog_center.dismiss();
                    }
                });
            }

            if (signBean.getEarningsCard() != null) {
                if (signBean.getEarningsCard().getType() == 1) {
                    DialogUtil.getInstance().showCenterDialog(context, R.layout.dialog_sign_quicken_card);
                    LinearLayout dialog_sign_quicken_card = (LinearLayout) DialogUtil.getInstance().dialog_center_layout;
                    ImageView top_img = dialog_sign_quicken_card.findViewById(R.id.top_img);
                    top_img.setImageResource(R.mipmap.icon_two_card_bg);
                    TextView quicken_card_title = dialog_sign_quicken_card.findViewById(R.id.quicken_card_title);
                    quicken_card_title.setText("2倍收益体验卡");
                    TextView quicken_card_msg = dialog_sign_quicken_card.findViewById(R.id.quicken_card_msg);
                    quicken_card_msg.setText("每日任务奖励*2");
                    TextView quicken_card_msg_date = dialog_sign_quicken_card.findViewById(R.id.quicken_card_msg_date);
                    quicken_card_msg_date.setText("有效期至" + signBean.getEarningsCard().getEndTime().split("-")[1] + "月" + signBean.getEarningsCard().getEndTime().split("-")[2].split(" ")[0] + "日，现已生效");
                    TextView bottom_text = dialog_sign_quicken_card.findViewById(R.id.bottom_text);
                    bottom_text.setText("再签到" + 2 + "天可获得2倍收益卡");
                    TextView now_watch = dialog_sign_quicken_card.findViewById(R.id.now_watch);
                    now_watch.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isDoubleClick()) {
                                return;
                            }
                            DialogUtil.getInstance().dialog_center.dismiss();
                        }
                    });
                } else if (signBean.getEarningsCard().getType() == 2) {
                    DialogUtil.getInstance().showCenterDialog(context, R.layout.dialog_sign_quicken_card);
                    LinearLayout dialog_sign_quicken_card = (LinearLayout) DialogUtil.getInstance().dialog_center_layout;
                    ImageView top_img = dialog_sign_quicken_card.findViewById(R.id.top_img);
                    top_img.setImageResource(R.mipmap.icon_two_card_bg);
                    TextView quicken_card_title = dialog_sign_quicken_card.findViewById(R.id.quicken_card_title);
                    quicken_card_title.setText("2倍收益卡");
                    TextView quicken_card_msg = dialog_sign_quicken_card.findViewById(R.id.quicken_card_msg);
                    quicken_card_msg.setText("每日任务奖励*2");
                    TextView quicken_card_msg_date = dialog_sign_quicken_card.findViewById(R.id.quicken_card_msg_date);
                    quicken_card_msg_date.setText("有效期至" + signBean.getEarningsCard().getEndTime().split("-")[1] + "月" + signBean.getEarningsCard().getEndTime().split("-")[2].split(" ")[0] + "日，次日生效");
                    TextView bottom_text = dialog_sign_quicken_card.findViewById(R.id.bottom_text);
                    bottom_text.setText("再签到" + 4 + "天可获得3倍收益卡");
                    TextView now_watch = dialog_sign_quicken_card.findViewById(R.id.now_watch);
                    now_watch.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isDoubleClick()) {
                                return;
                            }
                            DialogUtil.getInstance().dialog_center.dismiss();
                        }
                    });
                } else if (signBean.getEarningsCard().getType() == 3) {
                    DialogUtil.getInstance().showCenterDialog(context, R.layout.dialog_sign_quicken_card);
                    LinearLayout dialog_sign_quicken_card = (LinearLayout) DialogUtil.getInstance().dialog_center_layout;
                    ImageView top_img = dialog_sign_quicken_card.findViewById(R.id.top_img);
                    top_img.setImageResource(R.mipmap.icon_three_card_bg);
                    TextView quicken_card_title = dialog_sign_quicken_card.findViewById(R.id.quicken_card_title);
                    quicken_card_title.setText("3倍收益卡");
                    TextView quicken_card_msg = dialog_sign_quicken_card.findViewById(R.id.quicken_card_msg);
                    quicken_card_msg.setText("每日任务奖励*3");
                    TextView quicken_card_msg_date = dialog_sign_quicken_card.findViewById(R.id.quicken_card_msg_date);
                    quicken_card_msg_date.setText("有效期至" + signBean.getEarningsCard().getEndTime().split("-")[1] + "月" + signBean.getEarningsCard().getEndTime().split("-")[2].split(" ")[0] + "日，次日生效");
                    TextView bottom_text = dialog_sign_quicken_card.findViewById(R.id.bottom_text);
                    bottom_text.setText("再签到" + 3 + "天可获得2倍收益卡");
                    TextView now_watch = dialog_sign_quicken_card.findViewById(R.id.now_watch);
                    now_watch.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (Utils.isDoubleClick()) {
                                return;
                            }
                            DialogUtil.getInstance().dialog_center.dismiss();
                        }
                    });
                }
            }
        }

        quickAdapter = new QuickAdapter<SignKeepBena>(context, R.layout.item_sign_card) {
            @Override
            protected void convert(BaseAdapterHelper helper, SignKeepBena item) {
                TextView sign_title = helper.getView(R.id.sign_title);
                sign_title.setText(item.getDayStr());
                TextView sign_text = helper.getView(R.id.sign_text);
                sign_text.setText(item.getDay() + "");
                ImageView quicken_card = helper.getView(R.id.quicken_card);
                ScaleLinearLayout sign_bg = helper.getView(R.id.sign_bg);
                ImageView signImg = helper.getView(R.id.signed_img);

                if (item.isSign()) {
                    sign_text.setVisibility(View.INVISIBLE);
                    signImg.setVisibility(View.VISIBLE);
                    quicken_card.setVisibility(View.INVISIBLE);

                    if (item.isCurrentDay()) {
                        sign_bg.setBackgroundColor(getResources().getColor(R.color.common_color));
                    } else {
                        sign_bg.setBackgroundColor(getResources().getColor(R.color.color_f3f3));
                    }

                } else {
                    signImg.setVisibility(View.INVISIBLE);
                    sign_text.setVisibility(View.VISIBLE);
                    sign_text.setTextColor(getResources().getColor(R.color.color_333));

                    if (item.isCurrentDay()) {
                        sign_bg.setBackgroundColor(getResources().getColor(R.color.common_color));
                    } else {
                        if (item.getCard() == 2) {
                            quicken_card.setVisibility(View.VISIBLE);
                            quicken_card.setImageResource(R.mipmap.icon_two_quicken_card);
                            sign_bg.setBackgroundColor(getResources().getColor(R.color.color_c269));
                            sign_text.setTextColor(getResources().getColor(R.color.color_c269));
                            sign_title.setTextColor(getResources().getColor(R.color.white));
                        } else if (item.getCard() == 3) {
                            quicken_card.setVisibility(View.VISIBLE);
                            quicken_card.setImageResource(R.mipmap.icon_three_quicken_card);
                            sign_bg.setBackgroundColor(getResources().getColor(R.color.color_5243));
                            sign_text.setTextColor(getResources().getColor(R.color.color_5243));
                            sign_title.setTextColor(getResources().getColor(R.color.white));
                        } else {
                            quicken_card.setVisibility(View.INVISIBLE);
                            sign_bg.setBackgroundColor(getResources().getColor(R.color.color_f3f3));
                            sign_title.setTextColor(getResources().getColor(R.color.color_333));
                            sign_text.setTextColor(getResources().getColor(R.color.color_333));
                        }
                    }

                }

            }
        };

        gridview.setAdapter(quickAdapter);


        newAdapter = new QuickAdapter<SignTaskBean.NewListBean>(context, R.layout.item_enery_task) {
            @Override
            protected void convert(BaseAdapterHelper helper, SignTaskBean.NewListBean item) {
                helper.setText(R.id.task, item.getTitle());
                helper.setText(R.id.enery, item.getComment());
                ImageView img = helper.getView(R.id.img);
                if (item.getSign().equals("perfection")) {
                    Glide.with(context)
                            .load(R.mipmap.icon_item_invite)
                            .dontAnimate()
                            .into(img);
                } else if (item.getSign().equals("invite")) {
                    Glide.with(context)
                            .load(R.mipmap.icon_item_invite)
                            .dontAnimate()
                            .into(img);
                } else if (item.getSign().equals("attention")) {
                    Glide.with(context)
                            .load(R.mipmap.icon_item_attention)
                            .dontAnimate()
                            .into(img);
                }
                TextView btn = helper.getView(R.id.btn);
                btn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (Utils.isDoubleClick()) {
                            return;
                        }
                        if ("perfection".equals(item.getSign())) {
                            startActivity(MineInfoActivity.class);
                        } else if ("attention".equals(item.getSign())) {
                            EventBus.getDefault().post("main_index_1");
                            finishActivity();
                        } else if ("invite".equals(item.getSign())) {
                            Bundle bundle4 = new Bundle();
                            bundle4.putString("inviteCode", mUserInfoBean.getUser().getInviteCode());
                            startActivity(InviteNewActivity.class, bundle4);
                        }
                    }
                });
            }
        };

        newListview.setAdapter(newAdapter);


        dateAdapter = new QuickAdapter<SignTaskBean.EverydayListBean>(context, R.layout.item_enery_task) {
            @Override
            protected void convert(BaseAdapterHelper helper, SignTaskBean.EverydayListBean item) {
                helper.setText(R.id.task, item.getTitle());
                helper.setText(R.id.enery, item.getComment());
                ImageView img = helper.getView(R.id.img);
                if (item.getSign().equals("share")) {
                    Glide.with(context)
                            .load(R.mipmap.icon_item_share)
                            .dontAnimate()
                            .into(img);
                } else if (item.getSign().equals("publish")) {
                    Glide.with(context)
                            .load(R.mipmap.icon_item_publish)
                            .dontAnimate()
                            .into(img);
                } else if (item.getSign().equals("look")) {
                    Glide.with(context)
                            .load(R.mipmap.icon_item_watch)
                            .dontAnimate()
                            .into(img);
                } else if (item.getSign().equals("comment")) {
                    Glide.with(context)
                            .load(R.mipmap.icon_item_comment)
                            .dontAnimate()
                            .into(img);
                } else if (item.getSign().equals("like")) {
                    Glide.with(context)
                            .load(R.mipmap.icon_item_praise)
                            .dontAnimate()
                            .into(img);
                }
                TextView btn = helper.getView(R.id.btn);
                btn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (Utils.isDoubleClick()) {
                            return;
                        }
                        if ("share".equals(item.getSign())) {
                            finalOkGo.requestHead(RequestType.POSTHEAD, Url.INVITE_TOP_INFO, null, Url.INVITE_TOP_INFO, new Callback<InviteTopBean>() {
                                @Override
                                public void onSuccess(InviteTopBean inviteTopBean) {
                                    dismissDialog();
                                    if (inviteTopBean.getCode() == Contacts.SUCCESS) {
                                        showShareDialog(inviteTopBean.getInviteUrl() + "?inviteCode=" + mUserInfoBean.getUser().getInviteCode(), inviteTopBean);
                                    }
                                }
                            });
                        } else if ("publish".equals(item.getSign())) {
                            Bundle bundle = new Bundle();
                            bundle.putString("flag", "out");
                            bundle.putInt("count", 9);
                            startActivity(CameraActivity.class, bundle);
                        } else if ("look".equals(item.getSign())) {
                            EventBus.getDefault().post("main_index_1");
                            finishActivity();
                        } else if ("comment".equals(item.getSign())) {
                            EventBus.getDefault().post("main_index_1");
                            finishActivity();
                        } else if ("like".equals(item.getSign())) {
                            EventBus.getDefault().post("main_index_1");
                            finishActivity();
                        }
                    }
                });
                if (item.getIsShow() != 1) {
                    btn.setText("已完成");
                    btn.setEnabled(false);
                } else {
                    btn.setText("去完成");
                    btn.setEnabled(true);
                }
            }
        };

        dateListview.setAdapter(dateAdapter);

    }

    @Override
    protected void initData() {

    }

    private void showShareDialog(String url, InviteTopBean inviteTopBean) {

        DialogUtil.getInstance().showBottomDialog(context, R.layout.dialog_share);
        LinearLayout dialog_share = (LinearLayout) DialogUtil.getInstance().dialog_bottom_layout;
        dialog_share.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Utils.isDoubleClick()) {
                    return;
                }
                DialogUtil.getInstance().dialog_bottom.dismiss();
            }
        });

        dialog_share.findViewById(R.id.share_wechat).setOnClickListener(view -> {
            if (Utils.isDoubleClick()) {
                return;
            }
            DialogUtil.getInstance().dialog_bottom.dismiss();
            WXShareUtil wxShareUtil = new WXShareUtil(context);
            wxShareUtil.registerWx();
            WechatLoginUtil.getInstance().setWechatCallBack(SignActivity.this);

            wxShareUtil.share(url,
                    inviteTopBean.getInviteTitle(),
                    inviteTopBean.getInviteDetails(),
                    "", wxShareUtil.SHARETOFRIEND);
            MobclickAgent.onEvent(ContextUtil.getContext(), "invitationID");
        });

        dialog_share.findViewById(R.id.share_wechat_friend).setOnClickListener(view -> {
            if (Utils.isDoubleClick()) {
                return;
            }
            DialogUtil.getInstance().dialog_bottom.dismiss();
            WXShareUtil wxShareUtil = new WXShareUtil(context);
            wxShareUtil.registerWx();
            WechatLoginUtil.getInstance().setWechatCallBack(SignActivity.this);
            wxShareUtil.share(url,
                    inviteTopBean.getInviteTitle(),
                    inviteTopBean.getInviteDetails(),
                    "", wxShareUtil.SHARETOPYQ);
            MobclickAgent.onEvent(ContextUtil.getContext(), "invitationID");
        });

        dialog_share.findViewById(R.id.share_qq).setOnClickListener(view -> {
            if (Utils.isDoubleClick()) {
                return;
            }
            DialogUtil.getInstance().dialog_bottom.dismiss();
            mTencent = Tencent.createInstance(Config.QQ_APP_ID, ContextUtil.getContext());
            Bundle params = new Bundle();
            params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
            params.putString(QQShare.SHARE_TO_QQ_TITLE, inviteTopBean.getInviteTitle());
            params.putString(QQShare.SHARE_TO_QQ_SUMMARY, inviteTopBean.getInviteDetails());
            params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, url);
            mTencent.shareToQQ(SignActivity.this, params, new BaseUiListener());
            shareSuccess();
        });

        dialog_share.findViewById(R.id.share_qq_space).setOnClickListener(view -> {
            if (Utils.isDoubleClick()) {
                return;
            }
            DialogUtil.getInstance().dialog_bottom.dismiss();
            mTencent = Tencent.createInstance(Config.QQ_APP_ID, context);
            Bundle params = new Bundle();
            params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE, QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT);
            params.putString(QzoneShare.SHARE_TO_QQ_TITLE, inviteTopBean.getInviteTitle() + "\n" + inviteTopBean.getInviteDetails());//选填
            params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, "");
            params.putString(QzoneShare.SHARE_TO_QQ_IMAGE_URL, "");
            params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, url);
            params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, new ArrayList<String>());
            mTencent.shareToQzone(SignActivity.this, params, new BaseUiListener());
            shareSuccess();
        });

        dialog_share.findViewById(R.id.share_weibo).setOnClickListener(view -> {
            if (Utils.isDoubleClick()) {
                return;
            }
            DialogUtil.getInstance().dialog_bottom.dismiss();
            WbSdk.install(ContextUtil.getContext(), new AuthInfo(ContextUtil.getContext(), Config.SINA_APP_KEY, Config.REDIRECT_URL, ""));
            WbShareHandler shareHandler = new WbShareHandler(SignActivity.this);
            shareHandler.registerApp();
            WeiboMultiMessage weiboMessage = new WeiboMultiMessage();
            weiboMessage.textObject = getTextObj(url, inviteTopBean.getInviteTitle() + "\n" + inviteTopBean.getInviteDetails());
            shareHandler.shareMessage(weiboMessage, false);
            shareSuccess();
        });

        dialog_share.findViewById(R.id.copy_link).setOnClickListener(view -> {
            if (Utils.isDoubleClick()) {
                return;
            }
            DialogUtil.getInstance().dialog_bottom.dismiss();
            ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            // 创建一个剪贴数据集，包含一个普通文本数据条目（需要复制的数据）
            ClipData clipData = ClipData.newPlainText(null, url);
            // 把数据集设置（复制）到剪贴板
            clipboard.setPrimaryClip(clipData);
            showToast("链接已复制");
            MobclickAgent.onEvent(ContextUtil.getContext(), "invitationID");
        });

        dialog_share.findViewById(R.id.copy_text).setVisibility(View.INVISIBLE);

        dialog_share.findViewById(R.id.black_list).setVisibility(View.INVISIBLE);
        dialog_share.findViewById(R.id.report).setVisibility(View.INVISIBLE);

    }

    private void shareSuccess() {
        MobclickAgent.onEvent(ContextUtil.getContext(), "invitationID");
        finalOkGo.requestHead(RequestType.POSTHEAD, Url.SHARE_FRIEND_SUCCESS, null, Url.SHARE_FRIEND_SUCCESS, new Callback<SendCodeBean>() {
            @Override
            public void onSuccess(SendCodeBean sendCodeBean) {
                if (sendCodeBean.getCode() == Contacts.SUCCESS) {

                } else {
                    if (sendCodeBean.getCode() == Contacts.TOKEN_EMPTY) {
                    } else {
                        showImageToas(sendCodeBean.getMsg());
                    }
                }
            }
        });
    }

    @Override
    public void onWbShareSuccess() {
//        showToast("分享成功");
    }

    @Override
    public void onWbShareCancel() {
//        showImageToas("分享取消");
    }

    @Override
    public void onWbShareFail() {
//        showImageToas("分享失败");
    }

    @Override
    public void callBack(BaseResp baseResp) {
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                showToast("分享成功");
                shareSuccess();
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                showImageToas("分享取消");
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                showImageToas("分享被拒绝");
                break;
            default:
                showImageToas("分享返回");
                break;
        }
    }

    private class BaseUiListener implements IUiListener {

        @Override
        public void onComplete(Object o) {
//            showToast("分享成功");
        }

        @Override
        public void onError(UiError uiError) {
//            showImageToas("分享失败");
        }

        @Override
        public void onCancel() {
//            showImageToas("分享取消");
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (mTencent != null) {
            mTencent.onActivityResult(requestCode, resultCode, data);
        }
    }


    private TextObject getTextObj(String url, String title) {
        TextObject textObject = new TextObject();
        textObject.text = title + "\n" + url;
        textObject.title = title;
        textObject.actionUrl = url;
        return textObject;
    }

    @Override
    protected void onStart() {
        super.onStart();
        showDialog(context, null);
        finalOkGo.requestHead(RequestType.POSTHEAD, Url.SIGN_TASK, null, Url.SIGN_TASK, new Callback<SignTaskBean>() {
            @Override
            public void onSuccess(SignTaskBean signTaskBean) {
                dismissDialog();
                if (signTaskBean.getCode() == Contacts.SUCCESS) {
                    if (signTaskBean.getEarningsCard() != null) {
                        if (signTaskBean.getEarningsCard().getType() == 1) {
                            quickenCard.setVisibility(View.VISIBLE);
                            quickenCard.setText("2倍收益中");
                            quickenCard.setBackgroundResource(R.drawable.shape_green_oval);
                        } else if (signTaskBean.getEarningsCard().getType() == 2) {
                            quickenCard.setVisibility(View.VISIBLE);
                            quickenCard.setText("2倍收益中");
                            quickenCard.setBackgroundResource(R.drawable.shape_green_oval);
                        } else if (signTaskBean.getEarningsCard().getType() == 3) {
                            quickenCard.setVisibility(View.VISIBLE);
                            quickenCard.setText("3倍收益中");
                            quickenCard.setBackgroundResource(R.drawable.shape_red_oval);
                        } else {
                            quickenCard.setVisibility(View.INVISIBLE);
                        }
                    } else {
                        quickenCard.setVisibility(View.INVISIBLE);
                    }

                    marqueeView.startWithList(signTaskBean.getBanner());
                    marqueeView.startFlipping();

                    if (signTaskBean.getSignInDay() >= 3) {
                        keep_sign.setText("再签到" + (7 - signTaskBean.getSignInDay()) + "天可获得3倍收益卡");
                    } else {
                        keep_sign.setText("再签到" + (3 - signTaskBean.getSignInDay()) + "天可获得2倍收益卡");
                    }

                    quickAdapter.clear();
                    for (int i = 0; i < 7; i++) {
                        SignKeepBena signKeepBena = new SignKeepBena();
                        signKeepBena.setDay(i + 1);
                        switch (i) {
                            case 0:
                                signKeepBena.setCard(0);
                                signKeepBena.setDayStr("第一天");
                                break;
                            case 1:
                                signKeepBena.setCard(0);
                                signKeepBena.setDayStr("第二天");
                                break;
                            case 2:
                                signKeepBena.setCard(2);
                                signKeepBena.setDayStr("第三天");
                                break;
                            case 3:
                                signKeepBena.setCard(0);
                                signKeepBena.setDayStr("第四天");
                                break;
                            case 4:
                                signKeepBena.setCard(0);
                                signKeepBena.setDayStr("第五天");
                                break;
                            case 5:
                                signKeepBena.setCard(0);
                                signKeepBena.setDayStr("第六天");
                                break;
                            case 6:
                                signKeepBena.setCard(3);
                                signKeepBena.setDayStr("第七天");
                                break;
                        }
                        if (signTaskBean.getSignInDay() == i + 1) {
                            signKeepBena.setCurrentDay(true);
                            signKeepBena.setDayStr("今天");
                        } else {
                            signKeepBena.setCurrentDay(false);
                        }
                        if (i + 1 > signTaskBean.getSignInDay()) {
                            signKeepBena.setSign(false);
                        } else {
                            signKeepBena.setSign(true);
                        }
                        quickAdapter.add(signKeepBena);
                    }
                    quickAdapter.notifyDataSetChanged();

                    newAdapter.clear();
                    for (int i = 0; i < signTaskBean.getNewList().size(); i++) {
                        if (signTaskBean.getNewList().get(i).getIsShow() == 1) {
                            newAdapter.add(signTaskBean.getNewList().get(i));
                        }
                    }
                    newAdapter.notifyDataSetChanged();

                    dateAdapter.clear();
                    dateAdapter.addAll(signTaskBean.getEverydayList());
                    dateAdapter.notifyDataSetChanged();

                } else {
                    if (signTaskBean.getCode() == Contacts.TOKEN_EMPTY) {
                    } else {
                        showImageToas(signTaskBean.getMsg());
                    }
                }
            }

            @Override
            public void onError(Response<String> response) {
                super.onError(response);
                dismissDialog();
            }
        });
    }


    @Override
    public void onStop() {
        super.onStop();
        marqueeView.stopFlipping();
    }
}
